package com.gjy.pd.decorator;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2022-12-23 10:00:27
 */
public class LogHelper {

    public static void main(String[] args) {
        Log log = new Logger();
        log.info("Hello");

        Log log4j = new Log4j(log);
        log4j.info("Hello Log4j");

        Logback logback = new Logback(log);
        logback.info("Hello Logback");

        Logback lb = new Logback(log4j);
        lb.info("Hello Logback log4j");
    }

    private interface Log {
        void info(String msg);
    }

    private static class Logger implements Log {

        @Override
        public void info(String msg) {
            System.out.println(msg);
        }
    }

    private static class Log4j implements Log {

        private final Log log;

        public Log4j(Log log) {
            this.log = log;
        }

        @Override
        public void info(String msg) {
            a();
            log.info(msg);
        }

        private void a() {
            System.out.println("log4j 处理");
        }
    }

    private static class Logback implements Log {

        private final Log log;

        public Logback(Log log) {
            this.log = log;
        }

        @Override
        public void info(String msg) {
            a();
            log.info(msg);
        }

        private void a() {
            System.out.println("Logback 处理");
        }
    }
}
